/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.candidat;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import gestionform.GestionInscriptionCandidat;
import model.Candidat;

/**
 *
 * @author Paul
 */
public class ServletInscriptionCandidat extends HttpServlet {
    private static final String ATT_GESTION_INSCRIPTION_CANDIDAT = "gInscriptCandidat";
    private static final String VUE_CREATION_COMPTE = "";

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Candidat c = (Candidat) request.getSession().getAttribute("candidat");
        if (c != null) {
            GestionInscriptionCandidat gInscriptCandidat = new GestionInscriptionCandidat(c);
            gInscriptCandidat.verifSaisieChamps(request);
            if (gInscriptCandidat.getErreurs().isEmpty()) {
                gInscriptCandidat.inscrireCandidat(c);
                request.setAttribute(ATT_GESTION_INSCRIPTION_CANDIDAT, gInscriptCandidat);
            }
            request.setAttribute(ATT_GESTION_INSCRIPTION_CANDIDAT, gInscriptCandidat);
            this.getServletContext().getRequestDispatcher(VUE_CREATION_COMPTE).forward(request, response);

        } else {
            request.getRequestDispatcher("view/connexion/connexion.jsp").forward(request, response);
        }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
